#################################################
#

def list_all_smarty_var file_name, regex
    if  File.exists? file_name 
        file = File.open file_name, 'r'
        content = file.read
        regex = /\{%\s*\$[a-zA-Z0-9_]+%\}/ if !regex
        content.scan(regex).each do
            |w| 
            yield(w) if block_given?
        end
    end
end

file_name, regexp_str = ARGV

if regexp_str
    regex = Regexp.new(regexp_str)
    p regex
end


# ruby smartyvars.rb <html-file-name> {%.*%}'
if !file_name
    puts 'ruby smartyvars.rb <html-file-name> {%.*%}'
else
    puts 'Search in ' + file_name
    puts '-' * 48
    list_all_smarty_var(file_name, regex) { |w| puts "#{w}\n" }
    puts '-' * 48
end



